

$(document).ready(function() {
    // var $stuName=$("input[name='stuName']").val();
    //var $sutNum=$("input[name='sutNum']").val();
    var $stuNum=20151010;
    // var $stuSex=$("input[name='stuSex']").val();
    // var $dormitoryNum=$("input[name='dormitoryNum']").val();
    // var $termYear=$("input[name='termYear']").val();
    // var $termNum=$("input[name='termNum']").val();
    var $termYear="2015-2016";
    var $termNum="第一学期";
    $("input[name='stuNum']").val("20151000");
    $("input[name='sutName']").val("小红");
    $("input[name='stuSex']").val("女");
    $("input[name='dormitoryNum']").val("824");
    $("input[name='termYear']").val("2015-2016");
    $("input[name='termNum']").val("第一学期");

    $.ajax({

        url:"http://localhost:8080/dormitory/canApply",
        type:"GET",
        data:"stuInfoId="+1+"&termId="+1,
        dataType:"json",
        success:function (data) {
            var msg="可以申请！请填写相关信息";
            console.log(data)
            if (data.code==0){
                $.each(data.data,function (key,value) {
                    if(key=="080101"){
                        msg=value+"3秒后跳回查询页面";
                        layer.msg(msg);
                        setTimeout('delayer()',3000)
                    }
                    if(key=="080102"){
                        msg=value+"3秒后跳回查询页面";
                        layer.msg(msg);
                        setTimeout('delayer()',3000)
                    }

                });
            } else {
                layer.msg(msg);
            }

        },
        error:function () {
            layer.msg("网络在开小差~稍后重试");
        }
    })

});

function delayer(){
    window.location="queryMyDormitoryApply.html";
}
function after(){

}
/*提交申请*/
$(document).on('click', '#apply-btn', function() {
    // var $stuName=$("input[name='stuName']").val();
    //var $sutNum=$("input[name='sutNum']").val();
    var $stuNum=20151000;
    // var $stuSex=$("input[name='stuSex']").val();
    // var $dormitoryNum=$("input[name='dormitoryNum']").val();
    // var $termYear=$("input[name='termYear']").val();
    // var $termNum=$("input[name='termNum']").val();
    var $termYear="2015-2016";
    var $termNum="第一学期";
    var $startDate=$("input[name='startDate']").val();
    var $endDate=$("input[name='endDate']").val();
    var $reason=$("textarea[name='reason']").val();


    $.ajax({

        url:"http://localhost:8080/dormitory/applyDor",
        type:"POST",
        data:"stuNum="+$stuNum+"&termYear="+$termYear+
        "&termNum="+$termNum+"&startDate="+$startDate+"&endDate="+$endDate+"&reason="+$reason,
        dataType:"json",
        success:function (data,status) {
            console.log(data.data)
            layer.alert("申请已提交，请等待老师批复。")
        },
        error:function (data) {
            layer.alert("申请失败，请尝试重试。")
        }
    })
});